function [ecog bci]=bciRawdata2Ecog(run,lengthInSec)

% [ecog bci]=bciRawdata2Ecog(run,lengthInSec)
% translates the globally saved rawdata of a run to an ecog struct
% lengthInSec is optional and can limit the length
% recommended toolbox: ecog
% see also: ecogPlotVariances

global GLOBALtrainDat;
global GLOBALbci;

bci=GLOBALbci;

if nargin<2,
    endSample = size(GLOBALtrainDat{run}.trainDat,2);
else
    endSample=round(lengthInSec*bci.srate);
end

ecog.data=double(GLOBALtrainDat{run}.trainDat(:, 1:endSample));
ecog.sampDur=1000/bci.srate;
ecog.selectedChannels=bci.preprocChan;
ecog.nSamp=size(ecog.data,2);
ecog.nBaselineSamp=0;
ecog.timebase=0:ecog.sampDur/1000:ecog.sampDur*(ecog.nSamp-1)/1000;
